package com.hly.tool.enoviaInterface;

import com.matrixone.apps.domain.DomainObject;
import matrix.db.BusinessInterface;
import matrix.db.BusinessInterfaceList;
import matrix.db.Context;
import matrix.db.Vault;
import matrix.util.MatrixException;

/**
 * @author ：Jack Hao
 * @date ：Created in 2021/11/17 14:23
 * @description：接口工具类
 */
public class EnoviaInterfaceUtil
{


    /**
     * 给一个对象添加接口
     * vault 为默认值  "eService Production"
     *
     * @param context       上下文
     * @param domainObject  Domainobject 对象
     * @param interfaceName 接口名称
     * @throws MatrixException
     */
    public void addInterface(Context context, DomainObject domainObject, String interfaceName) throws MatrixException
    {
        boolean flag = true;
        BusinessInterfaceList businessInterfaces = domainObject.getBusinessInterfaces(context);
        for (int i = 0; i < businessInterfaces.size(); i++)
        {
            BusinessInterface businessInterface = businessInterfaces.get(i);
            String interfaceName_i = businessInterface.getName();
            if (interfaceName_i.equals(interfaceName))
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            BusinessInterface businessInterface = new BusinessInterface(interfaceName, new Vault("eService Production"));
            domainObject.addBusinessInterface(context, businessInterface);
        }
    }


    /**
     * 给一个对象添加接口
     *
     * @param context       上下文
     * @param domainObject  Domainobject 对象
     * @param interfaceName 接口名称
     * @param vault         存储位置
     * @throws MatrixException
     */
    public void addInterface(Context context, DomainObject domainObject, String interfaceName, Vault vault) throws MatrixException
    {
        boolean flag = true;
        BusinessInterfaceList businessInterfaces = domainObject.getBusinessInterfaces(context);
        for (int i = 0; i < businessInterfaces.size(); i++)
        {
            BusinessInterface businessInterface = businessInterfaces.get(i);
            String interfaceName_i = businessInterface.getName();
            if (interfaceName_i.equals(interfaceName))
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            BusinessInterface businessInterface = new BusinessInterface(interfaceName, vault);
            domainObject.addBusinessInterface(context, businessInterface);
        }
    }

    /**
     * 给一个对象添加接口
     *
     * @param context       上下文
     * @param domainObject  Domainobject 对象
     * @param interfaceName 接口名称
     * @param vault         存储位置
     * @throws MatrixException
     */
    public void addInterface(Context context, DomainObject domainObject, String interfaceName, String vault) throws MatrixException
    {
        boolean flag = true;
        BusinessInterfaceList businessInterfaces = domainObject.getBusinessInterfaces(context);
        for (int i = 0; i < businessInterfaces.size(); i++)
        {
            BusinessInterface businessInterface = businessInterfaces.get(i);
            String interfaceName_i = businessInterface.getName();
            if (interfaceName_i.equals(interfaceName))
            {
                flag = false;
                break;
            }
        }
        if (flag)
        {
            BusinessInterface businessInterface = new BusinessInterface(interfaceName, new Vault(vault));
            domainObject.addBusinessInterface(context, businessInterface);
        }
    }


    /**
     * 给一个对象添加接口
     * vault 为默认值  "eService Production"
     *
     * @param context       上下文
     * @param objectId      对象 id
     * @param interfaceName 接口名称
     * @throws MatrixException
     */
    public void addInterface(Context context, String objectId, String interfaceName) throws MatrixException
    {

        DomainObject obj = DomainObject.newInstance(context, objectId);
        addInterface(context, obj, interfaceName);
    }


    /**
     * 给一个对象添加接口
     *
     * @param context       上下文
     * @param objectId      对象 id
     * @param interfaceName 接口名称
     * @throws MatrixException
     */
    public void addInterface(Context context, String objectId, String interfaceName, Vault vault) throws MatrixException
    {

        DomainObject obj = DomainObject.newInstance(context, objectId);
        addInterface(context, obj, interfaceName, vault);
    }


    /**
     * 给一个对象添加接口
     *
     * @param context       上下文
     * @param objectId      对象 id
     * @param interfaceName 接口名称
     * @throws MatrixException
     */
    public void addInterface(Context context, String objectId, String interfaceName, String vault) throws MatrixException
    {

        DomainObject obj = DomainObject.newInstance(context, objectId);
        addInterface(context, obj, interfaceName, vault);
    }


}
